﻿<%@ WebHandler Language="C#" Class="mailSettings" %>

using System;
using System.Web;
using AMCBO;
using AMCOBJ;
using System.Data;

public class mailSettings : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        //context.Response.Write("Hello World");
        if (!string.IsNullOrEmpty(context.Request.QueryString["case"]))
        {
            string swch = context.Request.QueryString["case"];
            switch (swch)
            {
                case "load":
                    settingsObj objSetting = new settingsObj();
                    settings settingBO = new settings();
                    objSetting.OutgoingMail = context.Request.QueryString["outmail"];
                    objSetting.InComingMail = context.Request.QueryString["inmail"];
                    objSetting.MailServer = context.Request.QueryString["mailserv"];
                    objSetting.PortNo = context.Request.QueryString["port"];
                    objSetting.EnSSL = context.Request.QueryString["ssl"];

                    int x = settingBO.insertMailSettings(objSetting);
                    if (x == 0)
                    {
                        context.Response.Write("y");
                    }
                    else
                    {
                        context.Response.Write("n");
                    }
                    break;
                case "get":
                    settings settBO = new settings();
                    DataTable dt = new DataTable();
                    string output = string.Empty;
                    try
                    {
                        dt = settBO.getMailSettings();
                        if (dt.Rows.Count > 0)
                        {
                            output = "[";
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                output += "{\"id\":\"" + dt.Rows[i]["id"] +
                                    "\",\"outMail\":\"" + dt.Rows[i]["outgoing"] +
                                    "\",\"inMail\":\"" + dt.Rows[i]["incoming"] +
                                    "\",\"mailServ\":\"" + dt.Rows[i]["mailserver"] +
                                    "\",\"portNo\":\"" + dt.Rows[i]["port"] +
                                    "\",\"enSSL\":\"" + dt.Rows[i]["ssl"] +
                                    //"\",\"prevImgFId\":\"" + boTheme[i].PreviewImageFileID +
                                    //"\",\"cssFId\":\"" + boTheme[i].CSSFileID +
                                    "\"},";
                            }
                            if (output[output.Length - 1] == ',')
                            {
                                output = output.Substring(0, output.Length - 1);
                            }
                            output += "]";
                        }
                        context.Response.Write(output);
                    }
                    catch
                    {
                        context.Response.Write("n");
                    }
                    context.Response.Write(output);
                    break;
                default:
                    break;
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}